package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/mojocn/base64Captcha"
	"net/http"
)

var store = base64Captcha.DefaultMemStore

func Captcha(c *gin.Context) {
	digit := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80)
	captcha := base64Captcha.NewCaptcha(digit, store)
	captchaId, base64Url, _, err := captcha.Generate()
	if err != nil {
		c.JSON(http.StatusNotFound, gin.H{
			"code": -1,
			"msg":  "获取失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "图形验证码获取成功",
		"data": map[string]interface{}{
			"CaptchaId": captchaId,
			"Base64Url": base64Url,
		},
	})
}
